<?php
/*
  $Id: categories.php $
  TomatoCart Open Source Shopping Cart Solutions
  http://www.tomatocart.com

  Copyright (c) 2009 Wuxi Elootec Technology Co., Ltd

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License v2 (1991)
  as published by the Free Software Foundation.
*/

  class osC_Boxes_compatible_models extends osC_Modules {
    var $_title,
        $_code = 'compatible_models',
        $_author_name = 'MobiSoft',
        $_author_www = 'http://www.mobisoft.ca',
        $_group = 'boxes';

    function osC_Boxes_compatible_models() {
      global $osC_Language;

      $this->_title = $osC_Language->get('box_compatible_models_heading');
    }

    function initialize() {
      global $osC_Database, $osC_Language;//, $osC_Compatible_Models;

      $Qbrand = $osC_Database->query('select m.brand_id as id, m.brand_name as text, m.brand_image as image from :table_brands m order by sort_order');
      $Qbrand->bindTable(':table_brands', TABLE_BRANDS);
      //$Qbrand->bindInt(':languages_id', $osC_Language->getID());
      $Qbrand->setCache('box-brands-' . $osC_Language->getCode(), 100);
      $Qbrand->execute();

//       $Qmodel = $osC_Database->query('select m.brand_id as brand_id,m.model_id as id, m.model_name as text, m.model_image as image from :table_models m order by brand_id,sort_order');
//       $Qmodel->bindTable(':table_models', TABLE_MODELS);
//       //$Qmodel->bindInt(':languages_id', $osC_Language->getID());
//       $Qmodel->setCache('box-models-' . $osC_Language->getCode(), 100);
//       $Qmodel->execute();


        $this->_content = '<ul id="modelsTree">';

        while ($Qbrand->next()) {
          $brand_name = $Qbrand->value('text');
		  $brand_id= $Qbrand->value('id');
          if (!empty($brand_name)) {
            //$this->_content .= '<li>' . osc_link_object(osc_href_link(FILENAME_DEFAULT, 'brand=' . $Qbrand->valueInt('id')), osc_image("images/brand/" . $Qbrand->value('image'), $Qbrand->value('text')));
            $this->_content .= '<li>' . osc_link_object(osc_href_link(FILENAME_DEFAULT, 'brand=' . $Qbrand->valueInt('id')), $Qbrand->value('text'));
            //$this->_content .= '<li>' . $Qbrand->value('text');
		  }
		  $Qmodel = $osC_Database->query('select m.brand_id as brand_id,m.model_id as id, m.model_name as text, m.model_image as image from :table_models m where m.brand_id=:brandId order by brand_id,sort_order');
		  $Qmodel->bindTable(':table_models', TABLE_MODELS);
		  $Qmodel->bindInt(':brandId',$brand_id);
		  //$Qmodel->bindInt(':languages_id', $osC_Language->getID());
		  $Qmodel->setCache('box-models-' . $brand_id . '-' . $osC_Language->getCode(), 100);
		  $Qmodel->execute();
		  
		 $this->_content .= '<ul>';
		  while($Qmodel->next()){
// 		 	if($Qmodel->value('brand_id') == $brand_id){
		  		//$this->_content .= '<li id="' . $Qmodel->value('id') . '">' . $Qmodel->value('text') .'</li>';
		  		$this->_content .= '<li id="' . $Qmodel->value('id') . '">' . osc_link_object(osc_href_link(FILENAME_DEFAULT,'variant=' . $Qmodel->valueInt('id')) .'&mname=' . $Qmodel->value('text'),$Qmodel->value('text')) .'</li>';
// 		  	}
		  }
		  $this->_content .= '</ul>';
		  $this->_content .=  '</li>';
        }
        
        $this->_content .= '</ul>';

      
      $Qbrand->freeResult();
      $Qmodel->freeResult();

    }

    function install() {
      global $osC_Database;

      parent::install();

      //$osC_Database->simpleQuery("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Show Product Count', 'BOX_CATEGORIES_SHOW_PRODUCT_COUNT', '1', 'Show the amount of products each category has', '6', '0', 'osc_cfg_use_get_boolean_value', 'osc_cfg_set_boolean_value(array(1, -1))', now())");
      //$osC_Database->simpleQuery("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Display Drop Down Menu', 'BOX_CATEGORIES_DISPLAY_DROP_DOWN_MENU', '1', 'Use MenuMatic to display drop down menu', '6', '1', 'osc_cfg_use_get_boolean_value', 'osc_cfg_set_boolean_value(array(1, -1))', now())");
     // $osC_Database->simpleQuery("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Drop Down Menu Effect', 'BOX_CATEGORIES_DROP_DOWN_MENU_EFFECT', 'slide & fade', 'Drop Down Menu Effect', '6', '2', 'osc_cfg_use_get_boolean_value', 'osc_cfg_set_boolean_value(array(\'fade\', \'slide\', \'slide & fade\'))', now())");
      //$osC_Database->simpleQuery("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Drop Down Menu Duration', 'BOX_CATEGORIES_DROP_DOWN_MENU_DURATION', '600', 'Drop Down Menu Duration', '6', '3', now())");
    }

    function getKeys() {
      if (!isset($this->_keys)) {
        $this->_keys = array('BOX_CATEGORIES_SHOW_PRODUCT_COUNT');
        }

      return $this->_keys;
    }
  }
?>